package com.kamistoat.meimeimall.meimeimallseckill.web;

import com.kamistoat.meimeimall.common.To.seckillTo.SecKillSessionTo;
import com.kamistoat.meimeimall.common.annotation.DubboAndHTTPExceptionCatch;
import com.kamistoat.meimeimall.common.utils.R;
import com.kamistoat.meimeimall.meimeimallseckill.dubbo.SecKillDubboInterfaceImpl;
import com.kamistoat.meimeimall.meimeimallseckill.feign.CouponFeignService;
import com.kamistoat.meimeimall.meimeimallseckill.service.SeckillSessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "首页操作")
@RestController
@RequestMapping("web")
public class HomePageController {

    @Autowired
    SeckillSessionService seckillSessionService;
    @Autowired
    CouponFeignService couponFeignService;

    @Autowired
    SecKillDubboInterfaceImpl secKillDubboInterface;

    /**
     * 带缓查询当前时间段的秒杀。如果当前时间段没有秒杀活动则显示下一场最近的秒杀。
     */
    @ApiOperation("带缓查询当前时间段正在进行的秒杀或最近的一场秒杀")
    @GetMapping("/current_seckill_session")
    @DubboAndHTTPExceptionCatch
    public R getCurrentSecKillSession() {
        SecKillSessionTo currentSecKillSession = seckillSessionService.getCurrentSecKillSession();
        return R.ok().put("currentSecKillSession", currentSecKillSession);
    }

}
